Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add soft delete to lsg bodies. #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

bijoysijo
Copy link

@bijoysijo bijoysijo commented Sep 24, 2021

Proposed Changes

  • Remove Destroy Action
  • Add Archived Flag
  • Add Routes
  • Configure View and Controller Actions for Soft Delete
  • Add Authorization for New Actions
  • Add Policy Scope in Index View
  • Add Scope to List Live LSGs

closes #100

Comment on lines 37 to 47
def archive
id = params[:lsg_body_id]
@lsg_body = LsgBody.find(id)
@lsg_body.archive!
redirect_to lsg_bodies_path
end

def unarchive
id = params[:lsg_body_id]
@lsg_body = LsgBody.find(id)
@lsg_body.unarchive!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These endpoints should have an authorized check.
Use pundit for writing policies for auth check
https://github.com/varvet/pundit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have rewritten the policy in lsg_bodies_policy. Needs review.

Comment on lines 14 to 20
def archive!
update(archived: true)
end

def unarchive!
update(archived: false)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in the controller itself as we aren't using this method anywhere else. It's good to add a scope instead that will list live LSG's

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Moved to the controller. Have added a scope to list live lsgs.

db/schema.rb Outdated
@@ -79,6 +79,8 @@
t.datetime "updated_at", precision: 6, null: false
t.string "code"
t.uuid "district_id", null: false
t.boolean "archive", default: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo. Rollback the current migration and drop archive field from lsg_body

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,5 @@
class AddArchivedToLsgBodies < ActiveRecord::Migration[6.1]
def change
add_column :lsg_bodies, :archived, :boolean, default: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a filed archived_at so that we could figure out when the record was archived?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep record of all archive actions when was archived and when was unarchived like we have logs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll then have :archived, :archived_at fields. Won't it be ideal to keep only one of these? Both the fields can serve as a flag. So should we only go with the :archived_at field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft deletes for LSGs
3 participants